#include "../3dparty/gtest-support.h"
#include "../include/linklist.h"
#include "../include/doublylinklist.h"

TEST( LinkListTest, ListTest )
{

    LinkList L;
    ElemType v[] = {23, 45, 56, 12, 88};
    ElemType e;

    EXPECT_EQ( OK, LinkListInit( &L ) );
    EXPECT_EQ( OK, LinkListCreate( &L, v, ARRAYSIZE( v ) ) );

    EXPECT_EQ( OK, LinkListInsertElem( &L, 2, 2 ) );
    EXPECT_EQ( OK, LinkListDeleteElem( &L, 2, &e ) );

    EXPECT_EQ( OK, LinkListGetElem( &L, 2, &e ) );
    EXPECT_EQ( 45, e );

    EXPECT_EQ( OK, LinkListReset( &L ) );
}

TEST( DoublyLinkListTest, ListTest )
{
    DoublyLinkList L;
    ElemType v[] = {23, 45, 56, 12, 88};

    ElemType e;

    EXPECT_EQ( OK, DoublyLinkListInit( &L ) );
    EXPECT_EQ( OK, DoublyLinkListCreate( &L, v, ARRAYSIZE( v ) ) );

    EXPECT_EQ( OK, DoublyLinkListGetElem( &L, 1, &e ) );
    EXPECT_EQ( 23, e );

    EXPECT_EQ( OK, DoublyLinkListDeleteElem( &L, 2, &e ) );
    EXPECT_EQ( 45, e );
    EXPECT_EQ( OK, DoublyLinkListGetElem( &L, 2, &e ) );
    EXPECT_EQ( 56, e );

    EXPECT_EQ( OK, DoublyLinkListPushBack( &L, 6 ) );
    EXPECT_EQ( 5, DoublyLinkListLength( &L ) );

    EXPECT_EQ( 5, DoublyLinkListFindElem( &L, 6 ) );
    EXPECT_EQ( 0, DoublyLinkListFindElem( &L, 99 ) );
	EXPECT_EQ( FALSE, DoublyLinkListEmpty(&L));

    DoublyLinkListTraverse( &L, DoublyLinkListOutPut );
    DoublyLinkListTraverseBack( &L, DoublyLinkListOutPut );

    EXPECT_EQ( OK, DoublyLinkListClear( &L ) );
	EXPECT_EQ( TRUE, DoublyLinkListEmpty(&L));
    EXPECT_EQ( OK, DoublyLinkListUnInit( &L ) );
}